package com.dpteam.dao.impl;

import com.dpteam.dao.MemberLevelDao;
import com.dpteam.model.MemberLevel;
import com.dpteam.util.Page;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: luolei
 * Date: 2016/1/8
 * Time: 9:08
 */
@Repository
public class MemberLevelDaoImpl extends BaseDaoImpl<MemberLevel> implements MemberLevelDao {

    @Override
    public MemberLevel findByLevel(int level) {
        String hql = "from MemberLevel where level = ?";
        return get(hql, level);
    }

    @Override
    public MemberLevel findByNote(String note) {
        String hql = "from MemberLevel where note = ?";
        return get(hql, note);
    }

    @Override
    public List<MemberLevel> findAll() {
        String hql = "from MemberLevel order by id ";
        return find(hql);
    }

    @Override
    public List<MemberLevel> findAllByPage(Page page) {
        String hql = "from MemberLevel order by id ";
        return find(hql, page);
    }

    @Override
    public void deleteById(int id) {
        MemberLevel memberLevel = get(MemberLevel.class, id);
        if (memberLevel != null) {
            delete(memberLevel);
        }
    }
}
